package com.wg.other.kmp;

/**
 * kmp 匹配
 */
public class KmpExamples {

    public static void main(String[] args) {
        String tempStr="ACBACESBSSFFSDS";
        String toMotch="SBSS";
        System.out.println(getExistLocation(tempStr,toMotch));
    }

    /**
     * 1.暴力匹配
     */
    public static Integer getExistLocation(String tempStr,String toMotch){
        Integer location=-1;
        char[] tempChs=tempStr.toCharArray();
        char[] toMotchChs=toMotch.toCharArray();
        int j=0;
        for (int i = 0; i < tempChs.length-1; i++) {
            if (tempChs[i]!=toMotchChs[j]){
                i=i-(j-1);
                j=0;
            }else{
                if(j==toMotchChs.length-1){
                    location=i-j;
                    break;
                }
                j++;
            }
        }
        return location;
    }

    /**
     * kmp
     */
    public static Integer getLocationByKmp(String tempStr,String toMotch){
        Integer location=-1;
        char[] tempChs=tempStr.toCharArray();
        char[] toMotchChs=toMotch.toCharArray();
        int j=0;
        for (int i = 0; i < tempChs.length-1; i++) {
            if(tempChs[i]!=toMotchChs[j]){

            }
        }
        return location;
    }

    /**
     * 获取指定字符next 数组
     */

}
